package org.example.config;

import org.example.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.Date;

@Component
public class ScheduleConfig {

    private final UserRepository userRepository;

    @Autowired
    public ScheduleConfig(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @Scheduled(cron = "0 0 0 * * ?")
    public void resetDailyCounters() {
        // 获取当前日期
        Date currentDate = java.sql.Date.valueOf(LocalDate.now());
        userRepository.resetDailyCounters(currentDate);
    }
}
